#include<iostream>
#include<iomanip>
#include<algorithm>
using namespace std;
int main()
{
	int n = 0;
	cin >> n;
	int a[15] = { 0 };
	for (int i = 0; i < n; i++)
	{
		a[i] = i + 1;
	}
	
	do
	{
		for (int i = 0; i < n; i++)
		{
			cout<<setw(5) << a[i] <<setw(5);
		}
		cout << endl;
	} while (next_permutation(a, a + n));
	return 0;
}